﻿<?php 
error_reporting(E_ERROR | E_PARSE);
// 	$var= array();	
// 	foreach ( simplexml_load_file ('http://www4.bcb.gov.br/feed/taxas.ashx')->channel->item as $item ){
// 		$var = ('<a href="%s">%s<a/>%s<br><br>', $item->link, $item->title, $item->description);
// 	}

$rss_tags = array('title','link','guid','comments','description','pubDate','category',);
$rss_item_tag = 'item';
$rss_url = 'http://www4.bcb.gov.br/feed/taxas.ashx';

$rssfeed = rss_to_array($rss_item_tag,$rss_tags,$rss_url);

echo '<pre>';
// print_r($rssfeed);
$cont = count($rssfeed);
$c = 0;
$qnt = 0;
$var = 'texto=';
while($c<=$cont){
	$title = strip_tags($rssfeed[$c]['title']);
	$description = strip_tags($rssfeed[$c]['description']);
// 	$description = htmlentities($description);
// 	$description = substr($description, 0, 5);
	$var .= $title.' '.$description.' ';
	$qnt = $qnt + strlen($title);
	$qnt = $qnt + strlen($description);
	++$c;
}
echo 'quantidade='.$qnt.'&';
echo $var;

function rss_to_array($tag, $array, $url) {
	$doc = new DOMdocument();
	$doc->load($url);
	$rss_array = array();
	$items = array();
	foreach($doc->getElementsByTagName($tag) AS $node) {
		foreach($array AS $key => $value) {
			$items[$value] = $node->getElementsByTagName($value)->item(0)->nodeValue;
		}
		array_push($rss_array, $items);
	}
	return $rss_array;
}